<?php

	class RegController extends CommonController{

		public $model;

		public function __init(){
			parent:: __init();
			$this->model = K('Shop_user');
		}

		public function index(){

			$this->dis('reg');
		}

		public function code(){
			$code = new Code();
			$code -> show();
		}

		public function validate_username(){
			$username = Q('post.username');
			$userInfo = $this->model->where("username='{$username}'")->find();
			//这里为什么不用isset($userInfo)
			if ($userInfo) {
				$arr = array('status'=>0,'message'=>'用户名已存在,请重新填写');
			}else{
				$arr = array('status'=>1,'message'=>'正确');
			}
			//相当于echo json_encode(arr);die;是hd框架的ajax返回
			$this->ajax($arr);
		}

		public function validate_code(){
			$code = strtoupper(Q('post.code'));
			$codePreg = strtoupper($_SESSION['code']);
			if ($code != $codePreg) {
				$arr = array('status'=>0,'message'=>'验证码不一致');
			}else{
				$arr = array('status'=>1,'message'=>'正确');
			}
			//相当于echo json_encode(arr);die;是hd框架的ajax返回
			$this->ajax($arr);
		}

		public function reg(){
			if (IS_POST) {
				$regData = array(
					'username' => Q('post.username'),
					'password' => md5(Q('post.password')),

					);

				$this->model->add($regData);

			}
			$this->success('注册成功',__ROOT__);
		}
	}













?>